<?php
class ControllerDeployAppConfig extends Controller {
    public function index(){
        $this->load->model('catalog/product');
        $this->load->model('tool/image');




        print_r($this->session->data['app']);
//        exit;
        $this->data['check_app_name_exist']=  $this->url->link('deploy/app/check_app_name_exist');
        $this->data['get_price_action']=  $this->url->link('deploy/app_config/getprice');

        if (isset($this->request->post['app_id'])) {
            $app_id = (int)$this->request->post['app_id'];
        } else {
            $app_id = 0;
        }


        $this->data['app_id']=$app_id;
        $product_info = $this->model_catalog_product->getProduct($app_id);


        //GET APP OPTION
        $products = $this->cart->getProducts();


        $app_deploy_option=array();
        foreach ($products as $product) {
            if($app_id==$product['product_id']){
                foreach ($product['option'] as $option) {
                    if ($option['type'] != 'file') {
                        $value = $option['option_value'];
                    } else {
                        $filename = $this->encryption->decrypt($option['option_value']);

                        $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
                    }

                    $option_data[] = array(
                        'name'  => $option['name'],
                        'value' => $value
                    );
                }
                foreach($option_data as $result){
                    $app_deploy_option[$result['name']]= $result['value'];

                }
            }
        }



        if(isset($this->session->data['app']['deploy_config'][$app_id]['params']['name'])){
            $this->data['app_name']  =$this->session->data['app']['deploy_config'][$app_id]['params']['name'];
        }else{
            $model_array=explode('_',$product_info['model']);
            $app_name=$model_array['1'];
            if(strlen($app_name)<3){
                $app_name=$app_name."_server";
            }
            $this->data['app_name']  = $app_name."_".substr(md5(uniqid(rand(), true)), 0, 9);
        }


        if (isset($this->request->post['vpc_name'])) {
            $this->data['vpc_name']  = $this->request->post['vpc_name'];
        } else {
            $this->data['vpc_name']  = "";
        }

        if (isset($this->request->post['subnet_name'])) {
            $this->data['subnet_name']  = $this->request->post['subnet_name'];
        } else {
            $this->data['subnet_name']  = "";
        }
//        //region related
//
		 if (isset($this->request->post['region'])) {
            $this->data['region']  = $this->request->post['region'];
        } else {
            $this->data['region']  = "";
        }
//
//         $this->data['regions'] = array(
//            "qingcloud_pek2"=>"青云北京2区","qingcloud_gd1"=>"青云广东1区","qingcloud_ap1"=>"青云亚太区"
//        );
//
//        //end of region

        if ($product_info['image']) {
            $this->data['thumb'] = $this->model_tool_image->resize($product_info['image'],200, 200);
        } else {
            $this->data['thumb'] = '';
        }


        $options=$this->model_catalog_product->getProductOptions($app_id);
        foreach($options as $option){
            if($option['option_description_label']=='host_type'){
               foreach($option['option_value'] as $result){
                   $this->data['host_types'][$result['option_value_label']]=$result['option_value_label']."(".$result['name'].")";
               }
            }
            if($option['option_description_label']=='os_type'){
               foreach($option['option_value'] as $result){
                   $this->data['os_types'][$result['option_value_label']]=$result['name'];
               }
            }
        }

        $deploy_config=$this->model_catalog_product->getProductDeploy($app_id);
		//super password related
		 if (isset($this->request->post['super_password'])) {
            $this->data['super_password']  = $this->request->post['super_password'];
        } else {
            $this->data['super_password']  =$this->session->data['app']['basic']['super_password'];
        }
		//end

        $this->data['text_select']= $this->language->get('text_select');
        $this->data['windows_safe_admin_password']=$this->session->data['app']['basic']['super_password'];

        foreach($deploy_config as $key =>$value){
            $this->data[$key]=$value;
        }
        //default value
        $parameter=(array)$this->session->data['app']['deploy_config'][$app_id]['params']['parameter'];


        if(isset($this->session->data['app']['deploy_config'][$app_id])){
            if(isset($parameter['access_app_control']['web_control'])){
                $this->data['web_control_status']=1;
                $this->data['web_control_value']=$parameter['access_app_control']['web_control']['port_mapping'];
            }else{
                $this->data['web_control_status']=0;
            }
            if(isset($parameter['access_app_control']['https_control'])){
                $this->data['mstsc_control_status']=1;
                $this->data['https_control_value']=$parameter['access_app_control']['https_control']['port_mapping'];
            }else{
                $this->data['https_control_status']=0;
            }

            if(isset($parameter['access_app_control']['mstsc_control'])){
                $this->data['mstsc_control_status']=1;
                $this->data['mstsc_control_value']=$parameter['access_app_control']['mstsc_control']['port_mapping'];
            }else{
                $this->data['mstsc_control_status']=0;
            }
            //fixed multi same ssh port in same vpc
            if(isset($parameter['access_app_control']['ssh_control'])){
                $this->data['ssh_control_status']=1;
                $this->data['ssh_control_value']=$parameter['access_app_control']['ssh_control']['port_mapping'];
            }else{
                $this->data['ssh_control_status']=0;
            }
            if(isset($parameter['access_app_control']['webmail_control'])){
                $this->data['webmail_control_status']=1;
                $this->data['webmail_control_value']=$parameter['access_app_control']['webmail_control']['port_mapping'];
            }else{
                $this->data['webmail_control_status']=0;
            }

            if(isset($parameter['access_app_control']['web_redirect_control'])){
                $this->data['web_redirect_control_status']=1;
                $this->data['web_redirect_control_value']=$parameter['access_app_control']['web_redirect_control']['port_mapping'];
            }else{
                $this->data['web_redirect_control_status']=0;
            }

            if(isset($parameter['access_app_control']['web_work_control'])){
                $this->data['web_work_control_status']=1;
                $this->data['web_work_control_value']=$parameter['access_app_control']['web_work_control']['port_mapping'];
            }else{
                $this->data['web_work_control_status']=0;
            }

            if(isset($parameter['access_app_control']['pop3_control'])){
                $this->data['pop3_control_status']=1;
                $this->data['pop3_control_value']=$parameter['access_app_control']['pop3_control']['port_mapping'];
            }else{
                $this->data['pop3_control_status']=0;
            }


            if(isset($parameter['access_app_control']['smtp_control'])){
                $this->data['smtp_control_status']=1;
                $this->data['smtp_control_value']=$parameter['access_app_control']['smtp_control']['port_mapping'];
            }else{
                $this->data['smtp_control_status']=0;
            }


            if(isset($parameter['access_app_control']['imap_control'])){
                $this->data['imap_control_status']=1;
                $this->data['imap_control_value']=$parameter['access_app_control']['imap_control']['port_mapping'];
            }else{
                $this->data['imap_control_status']=0;
            }


            if(isset($parameter['access_app_control']['server_control'])){
                $this->data['server_control_status']=1;
                $this->data['server_control_value']=$parameter['access_app_control']['server_control']['port_mapping'];
            }else{
                $this->data['server_control_status']=0;
            }


            if(isset($parameter['access_app_control']['file_server_control'])){
                $this->data['file_server_control_status']=1;
                $this->data['file_server_control_value']=$parameter['access_app_control']['file_server_control']['port_mapping'];
            }else{
                $this->data['file_server_control_status']=0;
            }


            if(isset($parameter['access_app_control']['upgradesvr_control'])){
                $this->data['upgradesvr_control_status']=1;
                $this->data['upgradesvr_control_value']=$parameter['access_app_control']['upgradesvr_control']['port_mapping'];
            }else{
                $this->data['upgradesvr_control_status']=0;
            }


            if(isset($parameter['access_app_control']['SessionServer_control'])){
                $this->data['SessionServer_control_status']=1;
                $this->data['SessionServer_control_value']=$parameter['access_app_control']['SessionServer_control']['port_mapping'];
            }else{
                $this->data['SessionServer_control_status']=0;
            }


            if(isset($parameter['access_app_control']['infoServer_control'])){
                $this->data['infoServer_control_status']=1;
                $this->data['infoServer_control_value']=$parameter['access_app_control']['infoServer_control']['port_mapping'];
            }else{
                $this->data['infoServer_control_status']=0;
            }


            if(isset($parameter['access_app_control']['offmsgsvr_control'])){
                $this->data['offmsgsvr_control_status']=1;
                $this->data['offmsgsvr_control_value']=$parameter['access_app_control']['offmsgsvr_control']['port_mapping'];
            }else{
                $this->data['offmsgsvr_control_status']=0;
            }

            if(isset($parameter['db_mysql']['mysql_db_password'])){
                $this->data['sql_default_password']=$parameter->db_mysql['mysql_db_password'];
            }
            if(isset($parameter['db_mysql']['mysql_db_name'])){
                $this->data['app_sql_name']=$parameter['db_mysql']['mysql_db_name'];
            }
            if(isset($parameter['db_mysql']['mysql_db_user'])){
                $this->data['sql_default_user']=$parameter['db_mysql']['mysql_db_user'];
            }
            if(isset($parameter['db_mysql']['mysql_root_password'])){
                $this->data['sql_root_password']=$parameter['db_mysql']['mysql_root_password'];
            }
        }

            if(isset($parameter['instance_type'])){
                $this->data['host_type']=$parameter['instance_type'];
            }else{
                if($app_deploy_option['host_type']){
                    $this->data['host_type']=$app_deploy_option['host_type'];
                }else{
                    $this->data['host_type']="";
                }
            }
        if(isset($parameter['os_type'])){
            $this->data['os_type']=$parameter['os_type'];
        }else{
            if($app_deploy_option['os_type']){
                $this->data['os_type']=$app_deploy_option['os_type'];
            }else{
                $this->data['os_type']="";
            }
        }

        $this->data['price'] = $this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/deploy/app_config.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/deploy/app_config.tpl';
        } else {
            $this->template = 'default/template/deploy/app_config.tpl';
        }

        $this->response->setOutput($this->render());

    }

    public function set(){

        $this->language->load('deploy/app_config');

        $json = array();
        // Validate if customer is logged in.
        if (!$this->customer->isLogged()) {
            $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
        }
        // Validate cart has products and has stock.
        if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
            $json['redirect'] = $this->url->link('checkout/cart');
        }
        // Validate VPC Name
        if (!$json) {
            if (!preg_match('/[^\x{4e00}-\x{9fa5}]+$/u', $this->request->post['super_password']) || (!$this->check->check_up_low_number_exist($this->request->post['super_password']))) {
                $json['error']['super_password'] = $this->language->get('error_password');
            }

            if (!preg_match('/^[0-9a-zA-Z_]{3,32}$/i', $this->request->post['app_name'])) {
                $json['error']['app_name'] = $this->language->get('error_app_name');
            }


            if ($this->backend->check_app_name_exist($this->request->post['app_name'], $this->customer->getEmail(), $this->customer->getPassPlain())) {
                $json['error']['app_name'] = $this->language->get('error_app_name_exist');
            }



            if(isset($this->request->post['mysql_db_name'])){
                if (!preg_match('/^[0-9a-zA-Z_-]{3,32}$/i', $this->request->post['mysql_db_name'])) {
                    $json['error']['mysql_db_name'] = $this->language->get('error_mysql_db_name');
                }
            }
            if(isset($this->request->post['mysql_db_user'])){
                if (!preg_match('/^[0-9a-zA-Z_]{3,32}$/i', $this->request->post['mysql_db_user'])) {
                    $json['error']['mysql_db_user'] = $this->language->get('error_mysql_db_user');
                }
            }
            if(isset($this->request->post['mysql_db_password'])){
                if (!preg_match('/[^\x{4e00}-\x{9fa5}]+/iu', $this->request->post['mysql_db_password'])) {
                    $json['error']['mysql_db_password'] = $this->language->get('error_mysql_db_password');
                }
            }
            if(isset($this->request->post['mysql_root_password'])){
                if (!preg_match('/[^\x{4e00}-\x{9fa5}]+/iu', $this->request->post['mysql_root_password'])) {
                    $json['error']['mysql_root_password'] = $this->language->get('error_mysql_root_password');
                }
            }
            if(isset($this->request->post['windows_domain_name'])){
                if (!preg_match('/^[0-9a-zA-Z_.]{3,32}$/i', $this->request->post['windows_domain_name'])) {
                    $json['error']['windows_domain_name'] = $this->language->get('error_windows_domain_name');
                }
            }
            if(isset($this->request->post['windows_netbios_name'])){
                if (!preg_match('/^[0-9a-zA-Z_]{3,32}$/i', $this->request->post['windows_netbios_name'])) {
                    $json['error']['windows_netbios_name'] = $this->language->get('error_windows_netbios_name');
                }
            }

            if(isset($this->request->post['windows_safe_admin_password'])){
                if (!preg_match('/^[0-9a-zA-Z_]{3,32}$/i', $this->request->post['windows_safe_admin_password'])) {
                    $json['error']['windows_safe_admin_password'] = $this->language->get('error_windows_safe_admin_password');
                }
            }

        }

        if (!$json) {
                    $this->load->model('catalog/product');
                    if (isset($this->request->post['app_id'])) {
                        $app_id = (int)$this->request->post['app_id'];
                    } else {
                        $app_id = 0;
                    }
                    $product_info = $this->model_catalog_product->getProduct($app_id);
                    $deploy_app_config=array();
                    

                    $deploy_app_config['instance_type']=$this->request->post['host_type'];
                    $json['result'][$this->language->get('text_item_instance_type')]=$this->request->post['host_type'];
                    $deploy_app_config['os_type']=$this->request->post['os_type'];
                    $json['result'][$this->language->get('text_item_os_type')]=$this->request->post['os_type'];
                    

                    if(isset($this->request->post['web_control_status'])){
                        $deploy_app_config['access_app_control']['web_control']=array(
                            "is_allowed"  => true,
                            "port_mapping"  => (int)$this->request->post['web_control_port_mapping']
                        );
                        $json['result'][$this->language->get('text_item_web_port').'-']=(int)$this->request->post['web_control_port_mapping'];

                    }
                    if(isset($this->request->post['mstsc_control_status'])){
                        $deploy_app_config['access_app_control']['mstsc_control']=array(
                            "is_allowed"  => true,
                            "port_mapping"  => (int)$this->request->post['mstsc_control_port_mapping']
                        );
                        $json['result'][$this->language->get('text_item_mstsc_port')]=(int)$this->request->post['mstsc_control_port_mapping'];
                    }
                    if(isset($this->request->post['ssh_control_status'])){
                        $deploy_app_config['access_app_control']['ssh_control']=array(
                            "is_allowed"  => true,
                            "port_mapping"  => (int)$this->request->post['ssh_control_port_mapping']
                        );
                        $json['result'][$this->language->get('text_item_ssh_port')]=(int)$this->request->post['ssh_control_port_mapping'];

                    }
                    if(isset($this->request->post['https_control_status'])){
                        $deploy_app_config['access_app_control']['https_control']=array(
                            "is_allowed"  => true,
                            "port_mapping"  => (int)$this->request->post['https_control_port_mapping']
                        );
                        $json['result'][$this->language->get('text_item_https_port')]=(int)$this->request->post['https_control_port_mapping'];
                    }
                    if(isset($this->request->post['webmail_control_status'])){
                        $deploy_app_config['access_app_control']['webmail_control']=array(
                            "is_allowed"  => true,
                            "port_mapping"  => (int)$this->request->post['webmail_control_port_mapping']
                        );
                        $json['result'][$this->language->get('text_item_webmail_port')]=(int)$this->request->post['webmail_control_port_mapping'];
                    }
                    if(isset($this->request->post['web_redirect_control_status'])){
                        $deploy_app_config['access_app_control']['web_redirect_control']=array(
                            "is_allowed"  => true,
                            "port_mapping"  => (int)$this->request->post['web_redirect_control_port_mapping']
                        );
                        $json['result'][$this->language->get('text_item_web_redirect_port')]=(int)$this->request->post['web_redirect_control_port_mapping'];
                    }

                    if(isset($this->request->post['web_work_control_status'])){
                        $deploy_app_config['access_app_control']['web_work_control']=array(
                            "is_allowed"  => true,
                            "port_mapping"  => (int)$this->request->post['web_work_control_port_mapping']
                        );
                        $json['result'][$this->language->get('text_item_web_work_port')]=(int)$this->request->post['web_work_control_port_mapping'];
                    }


            if(isset($this->request->post['pop3_control_status'])){
                $deploy_app_config['access_app_control']['pop3_control']=array(
                    "is_allowed"  => true,
                    "port_mapping"  => (int)$this->request->post['pop3_control_port_mapping']
                );
                $json['result'][$this->language->get('text_item_pop3_control_port')]=(int)$this->request->post['pop3_control_port_mapping'];
            }

            if(isset($this->request->post['smtp_control_status'])){
                $deploy_app_config['access_app_control']['smtp_control']=array(
                    "is_allowed"  => true,
                    "port_mapping"  => (int)$this->request->post['smtp_control_port_mapping']
                );
                $json['result'][$this->language->get('text_item_smtp_control_port')]=(int)$this->request->post['smtp_control_port_mapping'];
            }

            if(isset($this->request->post['imap_control_status'])){
                $deploy_app_config['access_app_control']['imap_control']=array(
                    "is_allowed"  => true,
                    "port_mapping"  => (int)$this->request->post['imap_control_port_mapping']
                );
                $json['result'][$this->language->get('text_item_imap_control_port')]=(int)$this->request->post['imap_control_port_mapping'];
            }

            if(isset($this->request->post['server_control_status'])){
                $deploy_app_config['access_app_control']['server_control']=array(
                    "is_allowed"  => true,
                    "port_mapping"  => (int)$this->request->post['server_control_port_mapping']
                );
                $json['result'][$this->language->get('text_item_server_control_port')]=(int)$this->request->post['server_control_port_mapping'];
            }

            if(isset($this->request->post['file_server_control_status'])){
                $deploy_app_config['access_app_control']['file_server_control']=array(
                    "is_allowed"  => true,
                    "port_mapping"  => (int)$this->request->post['file_server_control_port_mapping']
                );
                $json['result'][$this->language->get('text_item_file_server_control_port')]=(int)$this->request->post['file_server_control_port_mapping'];
            }

            if(isset($this->request->post['upgradesvr_control_status'])){
                $deploy_app_config['access_app_control']['upgradesvr_control']=array(
                    "is_allowed"  => true,
                    "port_mapping"  => (int)$this->request->post['upgradesvr_control_port_mapping']
                );
                $json['result'][$this->language->get('text_item_upgradesvr_control_port')]=(int)$this->request->post['upgradesvr_control_port_mapping'];
            }

            if(isset($this->request->post['SessionServer_control_status'])){
                $deploy_app_config['access_app_control']['SessionServer_control']=array(
                    "is_allowed"  => true,
                    "port_mapping"  => (int)$this->request->post['SessionServer_control_port_mapping']
                );
                $json['result'][$this->language->get('text_item_SessionServer_control_port')]=(int)$this->request->post['SessionServer_control_port_mapping'];
            }

            if(isset($this->request->post['infoServer_control_status'])){
                $deploy_app_config['access_app_control']['infoServer_control']=array(
                    "is_allowed"  => true,
                    "is_allowed"  => true,
                    "port_mapping"  => (int)$this->request->post['infoServer_control_port_mapping']
                );
                $json['result'][$this->language->get('text_item_infoServer_control_port')]=(int)$this->request->post['infoServer_control_port_mapping'];
            }



            if(isset($this->request->post['mysql_db_name'])){
                        $json['result'][$this->language->get('text_item_db_name')]=$this->request->post['mysql_db_name'];
                        $json['result'][$this->language->get('text_item_db_user')]=$this->request->post['mysql_db_user'];
                        $deploy_app_config['db_mysql']=array(
                            "mysql_db_name"  =>$this->request->post['mysql_db_name'],
                            "mysql_db_user"  => $this->request->post['mysql_db_user'],
                            "mysql_db_password"  => $this->request->post['mysql_db_password'],
                            "mysql_root_password"  => $this->request->post['mysql_root_password']
                        );
                    }

                    if(isset($this->request->post['windows_domain_name'])){
                        $json['result']['windows_domain_name']=$this->request->post['windows_domain_name'];
                        $json['result']['windows_netbios_name']=$this->request->post['windows_netbios_name'];
                        $deploy_app_config['windows_server_ad']=array(
                            "windows_domain_name"  =>$this->request->post['windows_domain_name'],
                            "windows_netbios_name"  => $this->request->post['windows_netbios_name'],
                            "windows_safe_admin_password"  => $this->session->data['app']['basic']['super_password'],
                        );
                    }else{
                        $deploy_app_config['windows_server_ad']=array(
                            "windows_domain_name"  =>'null',
                            "windows_netbios_name"  => 'null',
                            "windows_safe_admin_password"  => $this->session->data['app']['basic']['super_password'],
                        );
                    }

                    //web mail
                    $deploy_config=$this->model_catalog_product->getProductDeploy($app_id);
                    if($deploy_config['web_mail']){
                        $deploy_app_config['access_app_control']['https_control']=array(
                            "is_allowed"  => true,
                            "port_mapping"  => (int)$deploy_config['web_mail_value']
                        );
                    }
            //newly add for ssh key and password
            if(isset($this->request->post['ssh_key']) && !empty($this->request->post['ssh_key'])){

            	$admin_mode = 'ssh_public_key';
            }
            else{
            	$admin_mode = 'password';
            }


                    $data=array(
                        'app_id'        =>$app_id,
                        'model'               =>$product_info['model'],
                        'parameter'     =>$deploy_app_config,
                        'region'     =>$this->request->post['region'],
                        //"admin_mode"       =>'password',
                        "admin_mode"       =>$admin_mode,
                        'app_name'     =>$this->request->post['app_name'],
                        'vpc_name'     =>$this->request->post['vpc_name'],
                        'vxnet_name'     =>$this->request->post['subnet_name'],
                        'ssh_public_key'     =>$this->request->post['ssh_key'],
                        'super_password'     =>$this->request->post['super_password']
                    );
            $this->session->data['app']['product_price'][$app_id]=$this->request->post['price'];
        $this->session->data['app']['deploy_config'][$app_id]=$this->create_app_parameter($data);
        }

        $this->session->data['app']['deploy_app_info'][$app_id]=$json;

		//print_r( $this->session->data['app']['deploy_config']);
        $this->response->setOutput(json_encode($json));
    }

    public function create_app_parameter($data){

        $app= array(
            "url"=>"app_api",
            "cmd"=>"post",
            "params"=>array(
                "username"=>$this->customer->getEmail(),
                "app_type"=>$data['model'].$this->cart->getAppVersion($data['app_id']),
                "name"=>$data['app_name'],
                "region"=>$data['region'],
                "network"=>array(
                    "network_type"=>"vpc",
                    "vpc_mode"=>array(
                        "vpc_name"=>$data['vpc_name'],
                        "vxnet_name"=>$data['vxnet_name'],
                    )
                ),
                "administrator"=>array(
                    "admin_mode"=>$data['admin_mode'],
                    "password"=>$data['super_password'],
                    "ssh_public_key"=>array($data['ssh_public_key']),

                ),
                "parameter"=>(object)$data['parameter']
            )
        );

        return $app;
    }

    public function autoset(){
        $json = array();
        // Validate if customer is logged in.
        if (!$this->customer->isLogged()) {
            $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
        }
        if (!$json) {
            if(empty($this->request->post['vpc_name'])||empty($this->request->post['vpc_name'])){
                $json['error']= "error";
                exit;
            }
        }
        if (!$json) {
            if (isset($this->request->post['app_id'])) {
                $app_id = (int)$this->request->post['app_id'];
            } else {
                $app_id = 0;
            }
            $this->load->model('catalog/product');
            $product_info = $this->model_catalog_product->getProduct($app_id);

            $salt=substr(md5(uniqid(rand(), true)), 0, 9);
            $vpcname=$this->request->post['vpc_name'];
            $subnetname=$this->request->post['subnetname'];
            $passoword="Neucloud2014";
            $dbname1 = str_replace('app_', '', $product_info['model']);
            $dbname = str_replace('_full', '', $dbname1);
            $default_db_user="admin";
            $default_db_pass='admin';

            $this->session->data['app']['deploy_config'][$product_info['product_id']]=array(
                'url'=>"app_api",
                'cmd'=>"post",
                'params'=>array(
                    'username'   =>$this->customer->getEmail(),
                    'app_type'   =>$product_info['model'],
                    'name'   =>$product_info['model']."_". $this->customer->getId()."_".$salt,
                    'region'   =>"qingcloud_pek2",
                    'network'   =>array(
                        "network_type" => "vpc",
                        "vpc_mode"       => array(
                            "vpc_name"           =>$vpcname,
                            "vxnet_name"        =>$subnetname,
                        )
                    ),
                    "administrator"  =>array(
                        "admin_mode" =>"password",
                        "password" =>$passoword,
                    ),
                    "parameter"     =>array(
                        "instance_type"   => "c1m1",
                        "db_mysql"   =>array(
                            "mysql_db_name" =>$dbname,
                            "mysql_db_user" =>$default_db_user,
                            "mysql_db_password" =>$default_db_pass,
                            "mysql_root_password" =>$passoword,
                        )
                    )
                )
            );
            $json="succsess";
        }
        $this->response->setOutput(json_encode($json));
    }




    //get ssh key pair
     public function  fetch_app_ssh_key(){

     	 $region = $this->request->post['region'];
     	 $ssh_key = $this->backend->fetch_app_ssh_key($this->customer->getEmail(), $this->customer->getPassPlain(),$region);
     	 $this->response->setOutput(json_encode($ssh_key));


     }


    public function getprice()
    {
        $host_data=array(
            'cloud_type' => 'qingyun',
            'region' => $this->request->post['region'],
            'host_type' => $this->request->post['host_type'],
            'os_type' => $this->request->post['os_type'],
        );
        $price=$this->price->getPrice($host_data);

        //按月计算
        $json['text']="￥".($price*720).$this->language->get('price_symbole_mon');
        $json['val']=sprintf("%01.3f",$price*720);
            $json['val_hour']=sprintf("%01.3f",$price);
        $this->response->setOutput(json_encode($json));
    }
}